package cn.netbox.spring.handler;

import cn.netbox.spring.pojo.WXYStudent;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class WXYAspect {
    @Around(value = "execution(* cn.netbox.spring.service.impl.WXYServiceImpl.login(..))")
    public Object strong1(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object params[]=proceedingJoinPoint.getArgs();
        for (Object param:params
                ) {
            WXYStudent wxyStudent=(WXYStudent) param;
            if (wxyStudent.getEmail()==null){
                System.out.println("用户名不能为空");
            }else if (wxyStudent.getPassword()==null){
                System.out.println("密码不能为空");
            }else if (wxyStudent.getEmail()!="1255077403@qq.com" || wxyStudent.getPassword()!="123456"){
                System.out.println("用户名或密码错误");
            }else {
                proceedingJoinPoint.proceed();
            }

        }
        return null;
    }

    @Around(value = "execution(* cn.netbox.spring.service.impl.WXYServiceImpl.createStudent(..))")
    public Object strong2(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object params[]=proceedingJoinPoint.getArgs();
        for (Object param:params
             ) {
            WXYStudent wxyStudent=(WXYStudent) param;
            if (wxyStudent.getId()==null){
                System.out.println("未填写用户id");
            }else if (wxyStudent.getName()==null||wxyStudent.getName()==""){
                System.out.println("未填写用户名");
            }else if (wxyStudent.getEmail()==null||wxyStudent.getEmail()==""){
                System.out.println("未填写用户邮箱");
            }else if (wxyStudent.getPassword()==null||wxyStudent.getPassword()==""){
                System.out.println("未填写用户密码");
            }else {
                proceedingJoinPoint.proceed();
            }
        }



        return "这是增强操作";
    }
}
